package com.example.productmanagerspringboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.productmanagerspringboot.data.entity.MyUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

//单表用plus比较方便
@Mapper
public interface UserMapper extends BaseMapper<MyUser> {
    //老写法
//    @Select("select * from t_user where id=#{id}")
//    User findById(int id);
//
//    @Insert("insert into t_user(username,password) value(#{username},#{password})")
//    int insert(User user);
    //新写法，帮你写好了一些基本的方法
//
//    @Override
//    int insert(User entity);
//
//    @Override
//    User selectById(Serializable id);
    @Select("select * from t_user where username=#{username} && password=#{password}")
    MyUser login(String username, String password);

    //plus多表查询时比较复杂
    @Select("select * from t_user where id=#{id}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "username", property = "username"),
            @Result(column = "password", property = "password"),
            @Result(column = "id", property = "orderList", javaType = List.class, many = @Many(select = "com.example.productmanagerspringboot.mapper.OrderMapper.selectById"))
    })
    MyUser selectUserAndOrders(int id);
}
